#ifndef __ILIB_CORE_IO_RUNNER_H__
#define __ILIB_CORE_IO_RUNNER_H__

#include "../../iHeader.h"

class iIO;
class iIORunner
{
public:
	inline void add_io(iIO* io)
	{
        m_ios.push_front(io);

        on_io_join(io);
	}

    inline void remove_io(iIO* io)
    {
        for(std::list<iIO*>::iterator iter=m_ios.begin(); iter!=m_ios.end(); ++iter)
        {
            if(*iter != io)
                continue;
            m_ios.erase(iter);
            on_io_quit(io);
            return;
        }
    }

public:
	virtual int run() = 0;
    virtual void on_io_join(iIO*) { }
    virtual void on_io_quit(iIO*) { }

protected:
	std::list<iIO*> m_ios;
};

class iIOSelect : public iIORunner
{
public:
	virtual int run();
};

class iIOPoll : public iIORunner
{
public:
	virtual int run();
};
#if defined(__LINUX__)
struct epoll_event;
class iIOEPoll : public iIORunner
{
public:
    iIOEPoll();
    virtual void on_io_join(iIO*);
    virtual void on_io_quit(iIO*);
	virtual int  run();

private:
    #define EPOLL_SLOT_SIZE 1024
    int m_epoll;
    struct epoll_event* m_evs;
    std::map<int,struct epoll_event*> m_evh;
    std::map<int, iIO*> m_ios;

};
#endif

#endif  //__ILIB_CORE_IO_RUNNER_H__
